package com.sz.lk.wingsystem.mvp.presenter;

import com.sz.lk.wingsystem.bean.TaskResult;
import com.sz.lk.wingsystem.bean.TaskReturnResult;
import com.sz.lk.wingsystem.mvp.OnNetRequestListener;
import com.sz.lk.wingsystem.mvp.RxPresenter;
import com.sz.lk.wingsystem.mvp.contract.TaskContract;
import com.sz.lk.wingsystem.mvp.model.TaskModel;

/**
 * author : liuke
 * e-mail : 1012459343@qq.com
 * date   : 2020/12/6 18:12
 * desc   :
 * version: 1.0
 */
public class TaskPreserent extends RxPresenter<TaskContract.view> implements TaskContract.Presenter {
    private TaskContract.Model model = new TaskModel(this);

    @Override
    public void getTask(String code) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        model.task(code, new OnNetRequestListener<TaskResult>() {
            @Override
            public void onStart() {
                mView.showLoading();
            }

            @Override
            public void onFinish() {
                mView.hideLoading();
            }

            @Override
            public void onSuccess(TaskResult data) {
                mView.onTaskSuccess(data);
            }

            @Override
            public void onFailure(Throwable t) {

            }
        });
    }

    @Override
    public void getUploadTaskInfo(String id, String code, double weight, double volume,
                                  double length, double width, double height,
                                  String estimateChannel, String estimateAddress) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        model.UploadTaskInfo(id,code,weight,volume,length,width,height,estimateChannel,estimateAddress, new OnNetRequestListener<TaskReturnResult>() {
            @Override
            public void onStart() {
                mView.showLoading();
            }

            @Override
            public void onFinish() {
                mView.hideLoading();
            }

            @Override
            public void onSuccess(TaskReturnResult data) {
                mView.onUploadTaskInfoSuccess(data);
            }

            @Override
            public void onFailure(Throwable t) {
                mView.onError(t);
            }
        });
    }
}